set more 1

/*
File:	cepr_basic_empstat.do
Date:	Nov 21, 2006
		Feb 15, 2008
		Feb 10, 2009
		Jan  4, 2010
		Feb 22, 2011
		Jan  9, 2012
		Jan  4, 2013
		Dec 20, 2013
		Mar 12, 2015, CEPR ORG Version 2.0
		Apr  1, 2015, CEPR ORG Version 2.0.1
		Mar  1, 2016, CEPR ORG Version 2.1
		Oct 12, 2016, CEPR ORG Version 2.1.1
		Feb  9, 2017, CEPR ORG Version 2.2
		Apr 21, 2017, CEPR ORG Version 2.2.1
		Apr 10, 2018, CEPR ORG Version 2.3
		Mar 22, 2019, CEPR ORG Version 2.4
		Jul 24, 2019, CEPR ORG Version 2.4.1
	    Feb 05, 2020, CEPR ORG Version 2.5
	
Desc:	Creates consistent employment status variables for CEPR consistent
	extract	of Basic CPS
Note:	See copyright notice at end of program.
*/

/* note: any pre-1994 data processing is not yet correct;
         use only to process data from 1994 forward
*/

/* Determine data year */
local year=year in 1

/* Labor-market status */

gen byte lfstat=.

if `year'==1991 {
replace lfstat=1 if adlfsr==1 | adlfsr==2
replace lfstat=2 if adlfsr==3 | adlfsr==4
replace lfstat=3 if 5<=adlfsr & adlfsr<=7
}

if 1994<=`year' & `year'<=2020 {
replace lfstat=1 if pemlr==1 | pemlr==2
replace lfstat=2 if 3<=pemlr & pemlr<=4
replace lfstat=3 if 5<=pemlr & pemlr<=7
}
lab var lfstat "Labor-force status"
#delimit ;
lab def lfstat
1 Employed
2 Unemployed
3 NILF
;
#delimit cr
lab val lfstat lfstat
notes lfstat: CPS: derived from a-lfsr, pemlr


/* Employed */
gen byte empl=0 if lfstat~=.
replace empl=1 if lfstat==1
lab var empl "Employed"
notes empl: CPS: derived from a-lfsr, pemlr

/* Unemployed */
gen byte unem=0 if lfstat~=.
replace unem=1 if lfstat==2
lab var unem "Unemployed"
notes unem: CPS: derived from a-lfsr, pemlr

/* Not in labor force */
gen byte nilf=0 if lfstat~=.
replace nilf=1 if lfstat==3
lab var nilf "Not in labor force"
notes nilf: CPS: derived from a-lfsr, pemlr

/* Self-employed (unincorporated) */

gen byte selfemp=.

if `year'==1991 {
replace selfemp=0 if 1<=adclswkr & adclswkr<=8
replace selfemp=1 if adclswkr==6
}
if 1994<=`year' & `year'<=2020 {
replace selfemp=0 if 1<=peio1cow & peio1cow<=8
*replace selfemp=0 if (1<=peio1cow & peio1cow<=6) & peio1cow==8
replace selfemp=1 if peio1cow==7
}
lab var selfemp "Unincorporated self-employed - 1st job"
notes selfemp: Unincorporated self-employed only - primary job
notes selfemp: CPS: derived from a-clswkr, peio1cow

/* Incorporated self-employed */

gen byte selfinc=.

if `year'==1991 {
replace selfinc=0 if 1<=adclswkr & adclswkr<=8
replace selfinc=1 if adclswkr==5
}
if 1994<=`year' & `year'<=2020 {
replace selfinc=0 if 1<=peio1cow & peio1cow<=8
replace selfinc=1 if peio1cow==6
}
lab var selfinc "Incorporated self-employed - 1st job"
notes selfinc: Incorporated self-employed only - primary job
notes selfinc: CPS: derived from a-clswkr, peio1cow

/* Public sector */

gen byte pubsect=.

if `year'==1991 {
replace pubsect=0 if 1<=adclswkr & adclswkr<=8
replace pubsect=1 if 2<=adclswkr & adclswkr<=4
}
if 1994<=`year' & `year'<=2020 {
replace pubsect=0 if 1<=peio1cow & peio1cow<=8
replace pubsect=1 if 1<=peio1cow & peio1cow<=3
}
lab var pubsect "Public sector - 1st job"
notes pubsect: Federal, state, and local
notes pubsect: CPS: derived from a-clswkr, peio1cow

	/* Federal */

gen byte pubfed=.

if `year'==1991 {
replace pubfed=0 if 1<=adclswkr & adclswkr<=8
replace pubfed=1 if adclswkr==2
}
if 1994<=`year' & `year'<=2020 {
replace pubfed=0 if 1<=peio1cow & peio1cow<=8
replace pubfed=1 if peio1cow==1
}
lab var pubfed "Federal employee - 1st job"
notes pubfed: CPS: derived from a-clswkr, peio1cow

	/* State */

gen byte pubst=.

if `year'==1991 {
replace pubst=0 if 1<=adclswkr & adclswkr<=8
replace pubst=1 if adclswkr==3
}
if 1994<=`year' & `year'<=2020 {
replace pubst=0 if 1<=peio1cow & peio1cow<=8
replace pubst=1 if peio1cow==2
}
lab var pubst "State employee - 1st job"
notes pubst: CPS: derived from a-clswkr, peio1cow

	/* Local */
	
gen byte publoc=.

if `year'==1991 {
replace publoc=0 if 1<=adclswkr & adclswkr<=8
replace publoc=1 if adclswkr==4
}
if 1994<=`year' & `year'<=2020 {
replace publoc=0 if peio1cow~=. & peio1cow~=-1
replace publoc=1 if peio1cow==3
}
lab var publoc "Local employee"
notes publoc: CPS: derived from a-clswkr, peio1cow


/* Class of worker on 1st job */

gen byte cow1=.

if 1994<=`year' & `year'<=2020 {
replace cow1=peio1cow
replace cow1=. if peio1cow<=0
}

#delimit ;
lab def cow1
1 "GOVERNMENT - FEDERAL"
2 "GOVERNMENT - STATE"
3 "GOVERNMENT - LOCAL"
4 "PRIVATE, FOR PROFIT"
5 "PRIVATE, NONPROFIT"
6 "SELF-EMPLOYED, INCORPORATED"                                 
7 "SELF-EMPLOYED, UNINCORPORATED"
8 "WITHOUT PAY"
;
#delimit cr
lab val cow1 cow1

lab var cow1 "Class of Worker, 1st job"
notes cow1: CPS: peio1cow
notes cow1: Available 1994-present

/* Class of worker on 2nd job */

gen byte cow2=.

if 1994<=`year' & `year'<=2020 {
replace cow2=peio2cow
replace cow2=. if peio2cow<=0
}

#delimit ;
lab def cow2
1 "GOVERNMENT - FEDERAL"
2 "GOVERNMENT - STATE"
3 "GOVERNMENT - LOCAL"
4 "PRIVATE, FOR PROFIT"
5 "PRIVATE, NONPROFIT"
6 "SELF-EMPLOYED, INCORPORATED"                                 
7 "SELF-EMPLOYED, UNINCORPORATED"
8 "WITHOUT PAY"
;
#delimit cr
lab val cow2 cow2

lab var cow2 "Class of Worker, 2nd job"
notes cow2: CPS: peio2cow
notes cow2: Available 1994-present

/* Duration of Unemployment */

if 1979<=`year' & `year'<=1993 {
gen byte unemdur=.
gen byte jobloser=.
gen byte jobleaver=.
gen byte entrant=.
}
if 1994<=`year' & `year'<=2020 {
gen byte unemdur=.
replace unemdur=prunedur 
replace unemdur=. if prunedur<0
}
lab var unemdur "Unemployment duration (weeks)"
notes unemdur: Available 1994- only
notes unemdur: CPS: derived from prunedur

	/* job losers */

if 1994<=`year' & `year'<=2020 {
gen byte jobloser=0 if unem==1 & pruntype~=-1
replace jobloser=1 if unem==1 & pruntype==1 | pruntype==2 | pruntype==3
}
lab var jobloser "Job loser"
notes jobloser: Available 1994- only
notes jobloser: CPS derived from pruntype
notes jobloser: Includes those whose temporary job ended

	/* job leavers */

if 1994<=`year' & `year'<=2020 {
gen byte jobleaver=0 if unem==1 & pruntype~=-1
replace jobleaver=1 if unem==1 & pruntype==4 
}
lab var jobleaver "Job leaver"
notes jobleaver: Available 1994- only
notes jobleaver: CPS derived from pruntype

	/* entrants */

if 1994<=`year' & `year'<=2020 {
gen byte entrant=0 if unem==1 & pruntype~=-1
replace entrant=1 if unem==1 & pruntype==5 | pruntype==6
}
lab var entrant "Entrant"
notes entrant: Available 1994-present only
notes entrant: CPS derived from pruntype
notes entrant: Includes new and returning entrants

/* Union */

	/* Member */

gen byte unmem=.

if `year'<=1982 {
* not available
}
if `year'==1991 {
replace unmem=0 if adunmem==2
replace unmem=1 if adunmem==1
}
if 1994<=`year' & `year'<=2020 {
replace unmem=0 if peernlab==2 /* asked only if in months 4 & 8 */
replace unmem=1 if peernlab==1
}
lab var unmem "Union member"
notes unmem: Not available before 1983
notes unmem: CPS: a-unmem, peernlab

	/* Coverage */

gen byte uncov=.

if `year'<=1982 {
* not available
}
if `year'==1991 {
replace uncov=0 if aduncov==2
replace uncov=1 if aduncov==1
}
if 1994<=`year' & `year'<=2020 {
replace uncov=0 if peerncov==2  /* asked only if in months 4 & 8 */
replace uncov=1 if peerncov==1
}
lab var uncov "Union coverage"
notes uncov: Not available before 1983
notes uncov: Asked only if not a union member (i.e, only if peernlab==2)
notes uncov: CPS: a-uncov, peerncov

	/* Member or covered */
	
gen byte union=0 if unmem~=.
replace union=0 if uncov~=.

if 1983<=`year' &  `year'<=2020 {
replace union=1 if unmem==1
replace union=1 if uncov==1
}

lab var union "Union"
notes union: Not available before 1983
notes union: Union member or covered by union contract
notes union: CPS: derived from a-unmem, peernlab, a-uncov, peerncov


/* Professional Certification / Occupational Licensing */
/* Variable added in 2017: DOES <> HAVE A CURRENTLY ACTIVE PROFESSIONAL 
   CERTIFICATION OR A STATE OR INDUSTRY LICENSE? DO NOT INCLUDE BUSINESS 
   LICENSES, SUCH AS A LIQUOR LICENSE OR VENDING LICENSE. */
   
gen byte cert=.

if 2017<=`year'  &  `year'<=2020 {
replace cert=0 if pecert1==2
replace cert=1 if pecert1==1
}
lab var cert "Professional Certification"
notes cert: Available starting January 2017
notes cert: Active professional certification or state or industry license
notes cert: CPS: derived from pecert1

/* Was certification issued by the state, local, or federal government? */

gen byte certgov=.

if 2017<=`year'  &  `year'<=2020 {
replace certgov=0 if pecert2==2
replace certgov=1 if pecert2==1
}

lab var certgov "Certification was government issued"
notes certgov: Available starting January 2017
notes certgov: Professional certification state, local, or federal gov issued
notes certgov: CPS: derived from pecert2

/* School Enrollment Variables */

	/* Enrolled in school */
	
gen byte schenrl=.

if 1979<=`year' & `year'<=1983 {
* schenrl not available
}
if 1984<=`year' & `year'<=1993 {
replace schenrl=0 if aenrlw==2
replace schenrl=1 if aenrlw==1
}
if 1994<=`year' & `year'<=2020 {
replace schenrl=0 if peschenr==2
replace schenrl=1 if peschenr==1
}

lab var schenrl "Enrolled in HS or College last week"
notes schenrl: Not available before 1984
notes schenrl: Age 16-24 only
notes schenrl: From 1984-2012, valid for ages 16-24
notes schenrl: From 2013-on, valid for ages 16-54
notes schenrl: CPS: derived from a-enrlw, peschenr

	/* High School */
	
gen byte schhs=.

if 1979<=`year' & `year'<=1983 {
* schhs not available
}
if 1984<=`year' & `year'<=1993 {
replace schhs=0 if ahscol==2
replace schhs=1 if ahscol==1
}
if 1994<=`year' & `year'<=2020 {
replace schhs=0 if peschlvl==2
replace schhs=1 if peschlvl==1
}

lab var schhs "Enrolled in HS"
notes schhs: Not available before 1984
notes schhs: Age 16-24 only
notes schhs: From 1984-2012, valid for ages 16-24
notes schhs: From 2013-on, valid for ages 16-54
notes schhs: CPS: derived from a-hscol, peschlvl

	/* College */
	
gen byte schcol=.

if 1979<=`year' & `year'<=1983 {
* schcol not available
}
if 1984<=`year' & `year'<=1993 {
replace schcol=0 if ahscol==1
replace schcol=1 if ahscol==2
}
if 1994<=`year' & `year'<=2020 {
replace schcol=0 if peschlvl==1
replace schcol=1 if peschlvl==2
}
lab var schcol "Enrolled in College"
notes schcol: Not available before 1984
notes schcol: Age 16-24 only
notes schcol: From 1984-2012, valid for ages 16-24
notes schcol: From 2013-on, valid for ages 16-54
notes schcol: CPS: derived from a-hscol, peschlvl

	/* Full-time */
	
gen byte schft=.

if 1979<=`year' & `year'<=1983 {
* schft not available
}
if 1984<=`year' & `year'<=1993 {
replace schft=0 if aftpt==2 (16<=age & age<=24) 
replace schft=1 if aftpt==1 (16<=age & age<=24) 
}
if 1994<=`year' & `year'<=2020 {
replace schft=0 if peschft==2
replace schft=1 if peschft==1
}

lab var schft "Full-time Student"
notes schft: Not available before 1984
notes schft: Age 16-24 only
notes schft: CPS docs say underlying CPS variable only for /*
*/ ages 16-24 from 1984-2012, but small number are for higher ages in 89-93. /*
*/ For consistency, restricted ages 16-24
notes schft: From 1984-2012, valid for ages 16-24
notes schft: From 2013-on, valid for ages 16-54
notes schft: CPS: derived from a-ftpt, peschft
notes schft: Part-time students coded as zero

	/* Part-time */
	
gen byte schpt=.

if 1979<=`year' & `year'<=1983 {
* schpt not available
}
if 1984<=`year' & `year'<=1993 {
replace schpt=0 if aftpt==1 (16<=age & age<=24) 
replace schpt=1 if aftpt==2 (16<=age & age<=24) 
}
if 1994<=`year' & `year'<=2020 {
replace schpt=0 if peschft==1
replace schpt=1 if peschft==2
}
lab var schpt "Part-time Student"
notes schpt: Not available before 1984
notes schpt: Age 16-24 only
notes schpt: CPS docs say underlying CPS variable only for /*
*/ ages 16-24 from 1984-2012, but small number are for higher ages in 89-93. /*
*/ For consistency, restricted ages 16-24
notes schpt: From 1984-2012, valid for ages 16-24
notes schpt: From 2013-on, valid for ages 16-54
notes schpt: CPS: derived from a-ftpt, peschft
notes schpt: Full-time students coded as zero

/* More than one job */

gen byte multjob=.

if 1979<=`year' & `year'<=1993 {
* n.a. in NBER extract
}
if 1994<=`year' & `year'<=2020 {
replace multjob=0 if pemjot==2
replace multjob=1 if pemjot==1
}
lab var multjob "Has more than one job"
notes multjob: Not available before 1994
notes multjob: Universe: lfstat==1
notes multjob: CPS: derived from pemjot

gen byte multjobn=.

if 1979<=`year' & `year'<=1993 {
* n.a. in NBER extract
}
if 1994<=`year' & `year'<=2020 {
replace multjobn=1 if lfstat==1
replace multjobn=2 if pemjnum==2
replace multjobn=3 if pemjnum==3
replace multjobn=4 if pemjnum==4
}
lab var multjobn "Number of jobs"
notes multjobn: Number 4 corresponds to four or more
notes multjob: Not available before 1994
notes multjob: Universe: lfstat==1
notes multjob: CPS: derived from pemjot, pemjnum
			  
/* Paid Employees Information */

gen byte pdemp1=.

if 1979<=`year' & `year'<=2013 {
* pdemp1 not available
}
if 2014<=`year' & `year'<=2020 {
replace pdemp1=0 if pepdemp1==2
replace pdemp1=1 if pepdemp1==1
}

lab var pdemp1 "Usually has paid employees"
notes pdemp1: CPS: derived from pepdemp1
notes pdemp1: not available before 2014
notes pdemp1: only asked if hrmis=3 or 4

gen byte pdemp2=.

if 1979<=`year' & `year'<=2013 {
* pdemp2 not available
}
if 2014<=`year' & `year'<=2020 {
replace pdemp2=0 if pepdemp2==2
replace pdemp2=1 if pepdemp2==1
}

lab var pdemp2 "Usually has paid employees"
notes pdemp2: CPS: derived from pepdemp2
notes pdemp2: not available before 2014
notes pdemp2: only asked if hrmis=3 or 4

gen byte nmemp1=.

if 1979<=`year' & `year'<=2013 {
* nmemp1 not available
}
if 2014<=`year' & `year'<=2020 {
replace nmemp1=ptnmemp1
replace nmemp1=. if ptnmemp1<0 | ptnmemp1>75
}

lab var nmemp1 "Number of paid employees"
notes nmemp1: CPS: derived from ptnmemp1
notes nmemp1: not available before 2014
notes nmemp1: only asked if hrmis=3 or 4

gen byte nmemp2=.

if 1979<=`year' & `year'<=2013 {
* nmemp2 not available
}
if 2014<=`year' & `year'<=2020 {
replace nmemp2=ptnmemp2
replace nmemp2=. if ptnmemp2<0 | ptnmemp2>10
}

lab var nmemp2 "Number of paid employees"
notes nmemp2: CPS: derived from ptnmemp2
notes nmemp2: not available before 2014
notes nmemp2: only asked if hrmis=3 or 4


/* 
Copyright 2020 CEPR and John Schmitt

This file is part of the cepr_org_master.do program. This file and all
programs referenced in it are free software. You can redistribute the
program or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA.
*/


